<admintpl file="header" />

<link href="__TMPL__Public/assets/css/infomation.css" rel="stylesheet" />
<link type="text/css" href="__PUBLIC__/js/select2/select2.min.css" rel="stylesheet" />
</head>
<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('WorkingMemo/index')}">工作便函管理</a></li>
            <li class="active"><a href="{:U('WorkingMemo/add')}">新增工作便函</a></li>
        </ul>  
        <section class="tab-pane active fade in" id="access">
            <div class="row">
                <div class="col-xs-12 col-md-12 col-lg-12">
                    <div class="panel panel-info">

                        <div class="panel-body">
                            <form class="form-horizontal form-inline tg" action="{:U('WorkingMemo/add_post')}" method="post">
                                <div class="row tg-header">
                                    <div class="col-md-12 text-center">
                                        <p style="font-size:32px; line-height:35px; color:red; padding:20px;">杭州市中医院丁桥分院工作便函</p>
                                        <hr/>
                                    </div>
                                    <div class="col-md-12 text-center">
                                        <p class="text-center "><span>市中丁桥便函<input type="text" class="input-xt" name="code" required />号:</span></p>
                                    </div>
                                    <div class="col-md-12 text-center gzbh-title" style="margin:50px auto;">
                                        <p>
                                            <input type="text" name="title" style="width: 85%" class="input-xt input-deptname"/>
                                        </p>
                                    </div>
                                    <div class="well clearfix">
                                        <p class="tg-to">
                                            <label>
                                                发送：
                                                <!--input type="text" class="input-xt input-longname"  value="浙江泛华工程监理有限公司杭州市中医院丁桥分院项目部" />:-->
                                            </label>
                                            <select name="department_id" style="width:60%; background-color:white;  height:30px; border: 1px solid #aaa; border-radius:4px; cursor:text;" data-placeholder="选择发送单位:">
                                                <foreach name="data" item="vo">
                                                    <option <if condition="$vo.id eq $selectDefault">selected="selected"</if> value="{$vo.id}">{$vo.department_name}</option>
                                                </foreach>
                                            </select>
                                        </p>
                                        <p style="line-height:30px;text-indent:20px;padding-top:10px;">
                                            <textarea name="content" style="height: 200px;width: 95%"></textarea>
                                        </p>

                                        <div class="text-right" style="margin-top:50px;">
                                            <p style="margin-right: 70px;">杭州市中医院丁桥分院</p>
                                        </div>

                                        <p>
                                            <label>抄送:</label>
                                            <select name="carbon_copy_department[]" id="carbon_copy_department" style="width:60%;" class="select2" multiple="multiple" data-placeholder="选择抄送单位">
                                                <foreach name="data" item="vo">
                                                    <option value="{$vo.id}">{$vo.department_name}</option>
                                                </foreach>
                                            </select>
                                        </p>

                                        <div style="padding:10px 0px;">
                                            <label>附件:</label>
                                            <div class="controls">
                                                <a class="btn upBtn btn-primary" href="javascript:void(0);">上传</a>
                                                <input type="file" id="upFile" name="upFile" style="display:none" />
                                            </div>
                                        </div>

                                    </div>
                                </div>

                                <!-- <input type="hidden" name="id" value="{$id}" /> -->
                                <div class="form-actions">
                                    <button type="submit" class="btn btn-primary js-ajax-submit">{:L('ADD')}</button>
                                    <a class="btn btn-default" href="javascript:history.back(-1);">{:L('BACK')}</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </section>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <!--script src="__PUBLIC__/js/jquery.js"></script--><!--添加之后附件上传功能无法使用-->
    <script src="__PUBLIC__/js/select2/select2.min.js"></script>
    <script src="__PUBLIC__/js/select2/i18n/zh-cn.js"></script>
    <script src="__PUBLIC__/js/select2/select2.default.js"></script>
    <script type="text/javascript">
        $(document).ready(function (e) {
            $("select[name='contact_sheet_reporting_department']").change(function () {
                $("input[name='examination_and_approval_department']").val($("select[name='contact_sheet_reporting_department']").find("option:selected").text());
            });
            $("input[name='contact_sheet_code']").keyup(function () {
                $("input[id='code']").val($("input[name='contact_sheet_code']").val());
            });
        });
        $(function () {
            $(".select2").select2();
        });

        $(".btn-primary").click(function () {
            var relist = $("#carbon_copy_department").select2("data"); //多选
            console.log(relist);
            return true;
        })
    </script>





    <script>
        /* 多文件上传
        * @param reqUrl 请求地址
        * @param folder 上传后存储文件夹
        **/
        function UploadFile(reqUrl, folder){
            if($("#upFile").val() == ""){
                alert("请选择待上传文件！");
                return false;
            }
            $.ajaxFileUpload({
                url : reqUrl,
                secureuri : false, //安全协议
                fileElementId:'upFile', //id
                type : 'post',
                dataType : 'json',
                data:{
                    'folder'   : folder,
                    'ajax': 1
                },
                async : false,
                error : function(data,status,e) {
                    alert("服务器内部错误！");
                },
                success : function(json){
                    if (json.rtnType == 'T'){
                        var Cts = "HAIHUI" + json.file_type;
                        if(Cts.indexOf("image") > 0 ||  Cts.indexOf("pdf") > 0){
                            html = "<div class='controls' style='margin-top:10px;margin-left:10px'>   \n"
                                + " <input type='hidden' name='filePath[]' value='"+json.rtnResult+"' />    \n"
                                + " <input type='hidden' name='fileName[]' value='"+json.file_name+"' />    \n"
                                + " <input type='hidden' name='file_size[]' value='"+json.file_size+"' />   \n"
                                + " <input type='hidden' name='postfix[]' value='"+json.postfix+"' />     \n"
                                + " <a href='#' target='_blank'><label class=\"fileDownload\" path=\""+json.rtnResult+"\" name=\""+json.file_name+"\">"+json.file_name+"</label></a>\n"
                                + " <a href="+json.rtnResult+" target='_blank' class='btn btn-warning btn-xs'>查看</a>\n"
                                + " <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile'>删除</a> \n"
                                + "</div>";
                            $(".controls:last").after(html);
                        }else{
                            html = "<div class='controls' style='margin-top:10px;margin-left:10px'>   \n"
                                + " <input type='hidden' name='filePath[]' value='"+json.rtnResult+"' />    \n"
                                + " <input type='hidden' name='fileName[]' value='"+json.file_name+"' />    \n"
                                + " <input type='hidden' name='file_size[]' value='"+json.file_size+"' />   \n"
                                + " <input type='hidden' name='postfix[]' value='"+json.postfix+"' />     \n"
                                + " <a href='#' target='_blank'><label class=\"fileDownload\" path=\""+json.rtnResult+"\" name=\""+json.file_name+"\">"+json.file_name+"</label></a>\n"
                                + " <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile'>删除</a> \n"
                                + "</div>";
                            $(".controls:last").after(html);
                        }
                    } else {
                        alert(json.rtnMsg);
                    }
                },
                complete: function(xmlHttpRequest) {

                    $("#upFile").replaceWith('<input type="file" id="upFile" name="upFile" style="display:none" />');
                    $("#upFile").on("change", function(){
                        UploadFile(reqUrl, folder);
                    });
                }
            });
        }


        $(document).ready(function(e) {


            // 选择图片
            $(document).on("click", ".upBtn", function(e) {
                $("#upFile").click();
            });
            // 文件选择器change事件
            $("#upFile").on("change", function(){
                UploadFile("{:U('WorkingMemo/upload')}", "construction_laison_note");
            });
            $(document).on("click", ".delFile", function(){
                if($(this).attr("value") != undefined){
                    delFile("{:U('WorkingMemo/delFile')}", $(this).attr("value"), $(this))
                } else {
                    $(this).closest("div").remove();
                }
            });
            // 拼接一行
            $(".addLine").click(function(){
                var html =  "<tr>" +
                    "   <td><input type=\"text\" name=\"job_name[]\" /></td>" +
                    "   <td><input type=\"text\" name=\"this_week_count[]\" /></td>" +
                    "   <td><input type=\"text\" name=\"next_week_count[]\" /></td>" +
                    "   <td>" +
                    "       <input type=\"hidden\" name=\"plan_type[]\" value=\""+$(this).attr("type")+"\" >" +
                    "       <a class=\"btn delLine\" href=\"javascript:void(0);\">删除</a>" +
                    "   </td>" +
                    "</tr>";
                $(this).closest("thead").next().append(html);
            });
            // 删除一行
            $(document).on("click", ".delLine", function(){
                $(this).closest("tr").remove();
            });
        });
    </script>
</body>
</html>